﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using SelfMadeMillionaire.Core.DTOs;
using PagedList;

namespace SelfMadeMillionaire.Web.Infrastructure.ViewModels.Admin
{
	public class NewUserReportViewModel
	{
        public string ReportType { get; set; }
		public DateTime BegDate 
        {
            get
            {
                switch (ReportType)
                {
                    case "today":
                        return EndDate;
                        break;
                    case "week":
                        DayOfWeek startOfWeek = DayOfWeek.Monday;
                        int diff = EndDate.DayOfWeek - startOfWeek;
                        if (diff < 0)
                        {
                            diff += 7;
                        }

                        return EndDate.AddDays(-1 * diff).Date;
                        break;
                    case "month":
                        return new DateTime(EndDate.Year, EndDate.Month, 1);
                    case "quarter":
                        int quarterNumber = (EndDate.Month - 1) / 3 + 1;
                        return new DateTime(EndDate.Year, (quarterNumber - 1) * 3 + 1, 1);
                        break;
                    case "year":
                        return new DateTime(EndDate.Year, 1, 1);
                        break;
                }

                return EndDate;
            }
        }
        public DateTime EndDate 
        { 
            get 
            {
                return DateTime.Today.Date;
            } 
        }

        public string DateRange
        {
            get
            {
                return BegDate.ToString("MM/dd/yyyy") + " - " + EndDate.ToString("MM/dd/yyyy");
            }
        }

        public List<NewUserReportItemModel> Items { get; set; }
	}

    public class NewUserReportItemModel
    {
        public string DateRange { get; set; }
        public int CountFree { get; set; }
        public int CountSilver { get; set; }
        public int CountGold { get; set; }
        public int CountPlatinum { get; set; }
        public int CountTotal { get; set; }
    }

    public class SubscriptionPaymentsReportViewModel
    {
        public int Page { get; set; }
        public int PageT { get; set; }
        public string SortOrder { get; set; }

        public IPagedList<PayPalPaymentDto> Transactions { get; set; }
    }

    public class DailyNewUserReportViewModel
    {
        public List<DailyNewUserReportItemModel> Items { get; set; }
        public DateTime BegDate
        {
            get
            {
                return EndDate.AddDays(-13);
            }
        }

        public DateTime EndDate
        {
            get
            {
                return DateTime.Today.Date;
            }
        }
        public int SumTotal
        {
            get
            {
                if (Items == null)
                    return 0;

                return Items.Sum(i => i.CountTotal);
            }
        }
    }

    public class DailyNewUserReportItemModel
    {
        public DateTime Date { get; set; }
        public int CountFree { get; set; }
        public int CountSilver { get; set; }
        public int CountGold { get; set; }
        public int CountPlatinum { get; set; }
        public int CountTotal { get; set; }
    }
}
